package com.fire.control.system.support.util.code;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.codec.digest.DigestUtils;

public class DigestUtil {
	

	    /**
	     * Calculates the MD5 digest and returns the value as a 16 element <code>byte[]</code>.
	     *
	     * @param data
	     *            Data to digest
	     * @return MD5 digest
	     */
	    public static byte[] md5(final byte[] data) {
	        return DigestUtils.md5(data);
	    }

	    /**
	     * Calculates the MD5 digest and returns the value as a 16 element <code>byte[]</code>.
	     *
	     * @param data
	     *            Data to digest
	     * @return MD5 digest
	     * @throws IOException
	     *             On error reading from the stream
	     * @since 1.4
	     */
	    public static byte[] md5(final InputStream data) throws IOException {
	        return DigestUtils.md5(data);
	    }

	    /**
	     * Calculates the MD5 digest and returns the value as a 16 element <code>byte[]</code>.
	     *
	     * @param data
	     *            Data to digest
	     * @return MD5 digest
	     */
	    public static byte[] md5(final String data) {
	        return DigestUtils.md5(data);
	    }

	    /**
	     * Calculates the MD5 digest and returns the value as a 32 character hex string.
	     *
	     * @param data
	     *            Data to digest
	     * @return MD5 digest as a hex string
	     */
	    public static String md5Hex(final byte[] data) {
	        return DigestUtils.md5Hex(data);
	    }

	    /**
	     * Calculates the MD5 digest and returns the value as a 32 character hex string.
	     *
	     * @param data
	     *            Data to digest
	     * @return MD5 digest as a hex string
	     * @throws IOException
	     *             On error reading from the stream
	     * @since 1.4
	     */
	    public static String md5Hex(final InputStream data) throws IOException {
	        return DigestUtils.md5Hex(data);
	    }

	    /**
	     * Calculates the MD5 digest and returns the value as a 32 character hex string.
	     *
	     * @param data
	     *            Data to digest
	     * @return MD5 digest as a hex string
	     */
	    public static String md5Hex(final String data) {
	        return DigestUtils.md5Hex(data);
	    }


	    /**
	     * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-256 digest
	     * @since 1.4
	     */
	    public static byte[] sha256(final byte[] data) {
	        return DigestUtils.sha256(data);
	    }

	    /**
	     * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-256 digest
	     * @throws IOException
	     *             On error reading from the stream
	     * @since 1.4
	     */
	    public static byte[] sha256(final InputStream data) throws IOException {
	        return DigestUtils.sha256(data);
	    }

	    /**
	     * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-256 digest
	     * @since 1.4
	     */
	    public static byte[] sha256(final String data) {
	        return DigestUtils.sha256(data);
	    }

	    /**
	     * Calculates the SHA-256 digest and returns the value as a hex string.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-256 digest as a hex string
	     * @since 1.4
	     */
	    public static String sha256Hex(final byte[] data) {
	        return DigestUtils.sha256Hex(data);
	    }

	    /**
	     * Calculates the SHA-256 digest and returns the value as a hex string.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-256 digest as a hex string
	     * @throws IOException
	     *             On error reading from the stream
	     * @since 1.4
	     */
	    public static String sha256Hex(final InputStream data) throws IOException {
	        return DigestUtils.sha256Hex(data);
	    }

	    /**
	     * Calculates the SHA-256 digest and returns the value as a hex string.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-256 digest as a hex string
	     * @since 1.4
	     */
	    public static String sha256Hex(final String data) {
	        return DigestUtils.sha256Hex(data);
	    }

	    /**
	     * Calculates the SHA-384 digest and returns the value as a <code>byte[]</code>.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-384 digest
	     * @since 1.4
	     */
	    public static byte[] sha384(final byte[] data) {
	        return DigestUtils.sha384(data);
	    }

	    /**
	     * Calculates the SHA-384 digest and returns the value as a <code>byte[]</code>.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-384 digest
	     * @throws IOException
	     *             On error reading from the stream
	     * @since 1.4
	     */
	    public static byte[] sha384(final InputStream data) throws IOException {
	        return DigestUtils.sha384(data);
	    }

	    /**
	     * Calculates the SHA-384 digest and returns the value as a <code>byte[]</code>.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-384 digest
	     * @since 1.4
	     */
	    public static byte[] sha384(final String data) {
	        return DigestUtils.sha384(data);
	    }

	    /**
	     * Calculates the SHA-384 digest and returns the value as a hex string.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-384 digest as a hex string
	     * @since 1.4
	     */
	    public static String sha384Hex(final byte[] data) {
	        return DigestUtils.sha384Hex(data);
	    }

	    /**
	     * Calculates the SHA-384 digest and returns the value as a hex string.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-384 digest as a hex string
	     * @throws IOException
	     *             On error reading from the stream
	     * @since 1.4
	     */
	    public static String sha384Hex(final InputStream data) throws IOException {
	        return DigestUtils.sha384Hex(data);
	    }

	    /**
	     * Calculates the SHA-384 digest and returns the value as a hex string.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-384 digest as a hex string
	     * @since 1.4
	     */
	    public static String sha384Hex(final String data) {
	        return DigestUtils.sha384Hex(data);
	    }

	    /**
	     * Calculates the SHA-512 digest and returns the value as a <code>byte[]</code>.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-512 digest
	     * @since 1.4
	     */
	    public static byte[] sha512(final byte[] data) {
	        return DigestUtils.sha512(data);
	    }

	    /**
	     * Calculates the SHA-512 digest and returns the value as a <code>byte[]</code>.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-512 digest
	     * @throws IOException
	     *             On error reading from the stream
	     * @since 1.4
	     */
	    public static byte[] sha512(final InputStream data) throws IOException {
	        return DigestUtils.sha512(data);
	    }

	    /**
	     * Calculates the SHA-512 digest and returns the value as a <code>byte[]</code>.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-512 digest
	     * @since 1.4
	     */
	    public static byte[] sha512(final String data) {
	        return DigestUtils.sha512(data);
	    }

	    /**
	     * Calculates the SHA-512 digest and returns the value as a hex string.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-512 digest as a hex string
	     * @since 1.4
	     */
	    public static String sha512Hex(final byte[] data) {
	        return DigestUtils.sha512Hex(data);
	    }

	    /**
	     * Calculates the SHA-512 digest and returns the value as a hex string.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-512 digest as a hex string
	     * @throws IOException
	     *             On error reading from the stream
	     * @since 1.4
	     */
	    public static String sha512Hex(final InputStream data) throws IOException {
	        return DigestUtils.sha512Hex(data);
	    }

	    /**
	     * Calculates the SHA-512 digest and returns the value as a hex string.
	     * <p>
	     * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
	     * </p>
	     *
	     * @param data
	     *            Data to digest
	     * @return SHA-512 digest as a hex string
	     * @since 1.4
	     */
	    public static String sha512Hex(final String data) {
	        return DigestUtils.sha512Hex(data);
	    }


}
